/* WorldVectorField.cc -- Campo de mensagem do tipo float
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogo.ramos@usp.br>
 * GEAR - Grupo de Estudos Avançados em Robótica
 * <http://www.sel.eesc.usp.br/gear>
 *
 * This file is part of GEARMedula.
 * 
 * GEARMedula is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, version 3 of the License.
 * 
 * GEARMedula is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "WorldVectorField.hh"

int
WorldVectorField::ParseField( XDR * xdrs,
                              struct FieldContainer * field_container )
{
    switch (field_operation_)
    {
    case FIELDOPERATION_DECODE:
    {
        float * wvec = field_container->field_world_vector;
        unsigned int nelem = kWorldVectorLength;

        if( !xdr_array( xdrs,
                        (char**) &wvec,
                        &nelem,
                        kWorldVectorLength,
                        sizeof(float),
                        (xdrproc_t) xdr_float ) )
        {
            fprintf( stderr, "WorldVector:Não foi possível retirar o vetor World do stream.");
        }

    
        field_container->field_type = FIELDTYPE_WORLD_VECTOR;

        break;
    }
    case FIELDOPERATION_ENCODE:
    {
        float * wvec = field_container->field_world_vector;
        unsigned int nelem = kWorldVectorLength;

        if( !xdr_array( xdrs,
                        (char**) &wvec,
                        &nelem,
                        kWorldVectorLength,
                        sizeof(float),
                        (xdrproc_t) xdr_float ) )
        {
            fprintf( stderr, "Não foi possível adicionar o vetor World do stream.");
        }

        break;
    }
    case FIELDOPERATION_FREE:
    {
        break;
    }
    }

    return 0;
}
